﻿package mortal.game.view.mainUI.Navbar
{
    import com.greensock.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import mortal.common.shortcutsKey.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.mainUI.shortcutbar.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class NavbarModule extends View
    {
        public var btnBottomContainer:Sprite;
        public var roleBtn:GLoadedButton;
        private var packIcon:NavbarPackIcon;
        private var packBtn:GLoadedButton;
        private var skillBtn:GLoadedButton;
        private var friendBtn:GLoadedButton;
        private var copyIcon:NavbarCopyIcon;
        private var groupBtn:GLoadedButton;
        private var dailyBtn:GLoadedButton;
        private var forgeBtn:GLoadedButton;
        private var spriteBtn:GLoadedButton;
        private var guildBtn:GLoadedButton;
        private var upBtn:GLoadedButton;
        private var dowmBtn:GLoadedButton;
        private var shopBtn:GLoadedButton;
        private var shoortCutKey:Array;

        public function NavbarModule()
        {
            this.shoortCutKey = ShortcutsKey.instance.moduleAry;
            this.layer = GameController.shortcut.view as ILayer;
            return;
        }// end function

        override protected function configUI() : void
        {
            super.configUI();
            this.btnBottomContainer = UIFactory.sprite();
            this.addChild(this.btnBottomContainer);
            this.roleBtn = UIFactory.gLoadedButton(ImagesConst.NavRole_upSkin, 0, 0, 40, 43, this.btnBottomContainer);
            this.roleBtn.name = ModuleType.Players;
            this.roleBtn.toolTipData = this.getPlayerBtnToolTip;
            this.packIcon = new NavbarPackIcon();
            this.packIcon.x = 0;
            this.packIcon.y = 0;
            this.packIcon.name = ModuleType.Pack;
            this.btnBottomContainer.addChild(this.packIcon);
            this.packBtn = this.packIcon.setStyle(ImagesConst.NavPack_upSkin, 40, 43);
            this.packBtn.toolTipData = this.getPackBtnToolTip;
            this.skillBtn = UIFactory.gLoadedButton(ImagesConst.NavSkill_upSkin, 0, 0, 40, 43, this.btnBottomContainer);
            this.skillBtn.name = ModuleType.Skills;
            this.skillBtn.toolTipData = this.getSkillBtnToolTip;
            this.spriteBtn = UIFactory.gLoadedButton(ImagesConst.NavSprite_upSkin, 0, 0, 40, 43, this.btnBottomContainer);
            this.spriteBtn.name = ModuleType.Wizard;
            this.spriteBtn.toolTipData = this.getWizardBtnToolTip;
            this.forgeBtn = UIFactory.gLoadedButton(ImagesConst.NavForge_upSkin, 0, 0, 40, 43, this.btnBottomContainer);
            this.forgeBtn.name = ModuleType.Build;
            this.forgeBtn.toolTipData = this.getForgeBtnToolTip;
            this.guildBtn = UIFactory.gLoadedButton(ImagesConst.NavClan_upSkin, 0, 0, 40, 43, this.btnBottomContainer);
            this.guildBtn.name = ModuleType.Guild;
            this.guildBtn.toolTipData = this.getGuildBtnToolTip;
            this.friendBtn = UIFactory.gLoadedButton(ImagesConst.NavFriend_upSkin, 0, 0, 40, 43, this.btnBottomContainer);
            this.friendBtn.name = ModuleType.Friend;
            this.friendBtn.toolTipData = this.getFriendBtnToolTip;
            this.groupBtn = UIFactory.gLoadedButton(ImagesConst.NavGroup_upSkin, 298, -1, 40, 43, this.btnBottomContainer);
            this.groupBtn.name = ModuleType.Group;
            this.groupBtn.toolTipData = this.getGroupBtnToolTip;
            this.dailyBtn = UIFactory.gLoadedButton(ImagesConst.NavDaily_upSkin, 0, 0, 40, 43, this.btnBottomContainer);
            this.dailyBtn.name = ModuleType.Daily;
            this.dailyBtn.toolTipData = this.getDailyBtnToolTip;
            this.shopBtn = UIFactory.gLoadedButton(ImagesConst.NavShop_upSkin, 378, -14, 44, 54, this.btnBottomContainer);
            this.shopBtn.name = ModuleType.ShopMall;
            this.shopBtn.toolTipData = this.getShopBtnToolTip;
            Dispatcher.dispatchEvent(new DataEvent(EventName.BtnComplete, this.btnBottomContainer));
            this.addEventListener(MouseEvent.CLICK, this.openWinHandeler);
            this.stageResize();
            return;
        }// end function

        private function openWinHandeler(event:MouseEvent) : void
        {
            var _loc_2:* = event.target;
            switch(_loc_2)
            {
                case this.packBtn:
                {
                    GameManager.instance.popupModuleType(ModuleType.Pack);
                    break;
                }
                case this.roleBtn:
                {
                    GameManager.instance.popupModuleType(ModuleType.Players);
                    break;
                }
                case this.skillBtn:
                {
                    GameManager.instance.popupModuleType(ModuleType.Skills);
                    break;
                }
                case this.shopBtn:
                {
                    GameManager.instance.popupModuleType(ModuleType.ShopMall);
                    break;
                }
                case this.guildBtn:
                {
                    GameManager.instance.popupModuleType(ModuleType.Guild);
                    break;
                }
                case this.forgeBtn:
                {
                    GameManager.instance.popupModuleType(ModuleType.Build);
                    break;
                }
                case this.groupBtn:
                {
                    GameManager.instance.popupModuleType(ModuleType.Group);
                    break;
                }
                case this.friendBtn:
                {
                    GameManager.instance.popupModuleType(ModuleType.Friend);
                    break;
                }
                case this.spriteBtn:
                {
                    GameManager.instance.popupModuleType(ModuleType.Wizard);
                    break;
                }
                case this.dailyBtn:
                {
                    GameManager.instance.popupModuleType(ModuleType.Daily);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function getNavbarIconGlobalPoint(param1:String) : Point
        {
            var _loc_2:* = this.btnBottomContainer.getChildByName(param1) as DisplayObject;
            if (_loc_2 != null)
            {
                return _loc_2.localToGlobal(new Point(0, 0));
            }
            return new Point(0, 0);
        }// end function

        public function shakeIcon(param1:String, param2:Number = -1) : void
        {
            var _loc_3:* = this.btnBottomContainer.getChildByName(param1) as DisplayObject;
            if (_loc_3 == null)
            {
                return;
            }
            NavbarShaker.instance.shake(_loc_3, param2);
            return;
        }// end function

        public function getNavbarIcon(param1:String) : DisplayObject
        {
            var _loc_2:* = this.btnBottomContainer.getChildByName(param1) as DisplayObject;
            return _loc_2;
        }// end function

        public function TweenFunc(param1:String) : void
        {
            if (param1 == "up")
            {
                TweenMax.to(this, 0.4, {delay:0.4, y:0});
            }
            else if (param1 == "down")
            {
                TweenMax.to(this, 0.4, {y:80});
            }
            return;
        }// end function

        override public function stageResize() : void
        {
            (GameController.shortcut.view as ShortcutBar).onStageResize();
            this.btnBottomContainer.x = 423;
            this.btnBottomContainer.y = GameController.shortcut.view.height - 58;
            return;
        }// end function

        private function getShortCutKeyByType(param1:String) : KeyMapData
        {
            var _loc_2:KeyMapData = null;
            var _loc_3:KeyMapData = null;
            for each (_loc_3 in this.shoortCutKey)
            {
                
                if (_loc_3.key == param1)
                {
                    _loc_2 = _loc_3;
                    break;
                }
            }
            return _loc_2;
        }// end function

        private function getPackBtnToolTip() : String
        {
            var _loc_1:* = this.getShortCutKeyByType(ModuleType.Pack);
            return Language.getStringByParam(35021, _loc_1.keyMapName, _loc_1.tempName);
        }// end function

        private function getPlayerBtnToolTip() : String
        {
            var _loc_1:* = this.getShortCutKeyByType(ModuleType.Players);
            return Language.getStringByParam(35022, _loc_1.keyMapName, _loc_1.tempName);
        }// end function

        private function getSkillBtnToolTip() : String
        {
            var _loc_1:* = this.getShortCutKeyByType(ModuleType.Skills);
            return Language.getStringByParam(35023, _loc_1.keyMapName, _loc_1.tempName);
        }// end function

        private function getFriendBtnToolTip() : String
        {
            var _loc_1:* = this.getShortCutKeyByType(ModuleType.Friend);
            return Language.getStringByParam(35024, _loc_1.keyMapName, _loc_1.tempName);
        }// end function

        private function getGroupBtnToolTip() : String
        {
            var _loc_1:* = this.getShortCutKeyByType(ModuleType.Group);
            return Language.getStringByParam(35025, _loc_1.keyMapName, _loc_1.tempName);
        }// end function

        private function getWizardBtnToolTip() : String
        {
            var _loc_1:* = this.getShortCutKeyByType(ModuleType.Wizard);
            return Language.getStringByParam(35026, _loc_1.keyMapName, _loc_1.tempName);
        }// end function

        private function getForgeBtnToolTip() : String
        {
            var _loc_1:* = this.getShortCutKeyByType(ModuleType.Build);
            return Language.getStringByParam(35027, _loc_1.keyMapName, _loc_1.tempName);
        }// end function

        private function getGuildBtnToolTip() : String
        {
            var _loc_1:* = this.getShortCutKeyByType(ModuleType.Guild);
            return Language.getStringByParam(35028, _loc_1.keyMapName, _loc_1.tempName);
        }// end function

        private function getDailyBtnToolTip() : String
        {
            var _loc_1:* = this.getShortCutKeyByType(ModuleType.Daily);
            return Language.getStringByParam(35029, Language.getString(35362), Language.getString(35363));
        }// end function

        private function getShopBtnToolTip() : String
        {
            var _loc_1:* = this.getShortCutKeyByType(ModuleType.ShopMall);
            return Language.getStringByParam(35030, _loc_1.keyMapName, _loc_1.tempName);
        }// end function

    }
}
